package com.cpj.bsyyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpj.bsyyzx.entity.NContent;
import com.cpj.bsyyzx.entity.NurseClass;
import com.cpj.bsyyzx.entity.NurseRecord;
import com.cpj.bsyyzx.service.INurseClassService;
import com.cpj.bsyyzx.service.INurseRecordService;
import com.cpj.bsyyzx.util.CommonResult;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/nurseRecord")
@Log4j
public class NurseRecordController {

    @Autowired
    INurseRecordService nurseRecordService;

    @RequestMapping("/list")
    CommonResult list(Page page, NurseRecord nurseRecord){
        QueryWrapper<NurseRecord> queryWrapper = new QueryWrapper<>();
        log.debug("分页查询");
        Page<NurseRecord> rpage=nurseRecordService.pageList(page, nurseRecord);
        return CommonResult.success(rpage);
    }


    @RequestMapping("save")
    @ResponseBody
    CommonResult save(NurseRecord nurseRecord) {
        log.debug("保存");
        Map map = new HashMap();
        boolean success = nurseRecordService.saveOrUpdate(nurseRecord);
        return CommonResult.success(success);
    }

    @RequestMapping("toedit")
    @ResponseBody
    public CommonResult toedit(ModelMap map, Integer nId) {
        log.debug("跳转到修改页面");
        NurseRecord nurseRecord = nurseRecordService.getById(nId);
        map.addAttribute("nurseRecord", nurseRecord);
        return CommonResult.success(nurseRecordService.getById(nId));
    }

    @RequestMapping("delete/{id}")
    @ResponseBody
    CommonResult delete(@PathVariable Integer id) {
        log.debug("根据主键删除:" + id);
        boolean success = nurseRecordService.removeById(id);
        return  CommonResult.success(success);
    }

    @RequestMapping("getByName")
    CommonResult getOneByName(String customer){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("customer",customer);
        return CommonResult.success(nurseRecordService.list(wrapper));
    }

}